package web.tag;

import domain.User;

import java.io.IOException;
import java.text.SimpleDateFormat;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * 详细信息展示标签
 * 结合modal实现user的详细信息的展示
 * 身份不同，展示的内容不同
 *
 * @author shicm
 */
public class ShowUserInfoTag extends SimpleTagSupport {

    /** 要展示的用户 */
    private User user;

    /** 用户身份 */
    private String identity;

    /**
     * 设置要展示的用户
     *
     * @param user 用户
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * 设置用户身份
     *
     * @param identity 身份
     */
    public void setIdentity(String identity) {
        this.identity = identity;
    }

    /**
     * 展示用户详细信息
     *
     * @throws JspException JSP异常
     * @throws IOException IO异常
     */
    @Override
    public void doTag() throws JspException, IOException {
        JspWriter out = getJspContext().getOut();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String outPrint = "";
        outPrint += "<p><span class=\"fw-semibold\">用户名: &nbsp;&nbsp;</span>"+user.getUsername()+"</p>";
        if (identity.equals("systemAdministrator")){
            outPrint += "<p><span class=\"fw-semibold\">密码:  &nbsp;&nbsp;</span>"+user.getPassword()+"</p>";
        }
        outPrint += "<p><span class=\"fw-semibold\">昵称:  &nbsp;&nbsp;</span>"+user.getNickname()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">性别:  &nbsp;&nbsp;</span>"+(user.getGender()?"男":"女")+"</p>";
        if (identity.equals("systemAdministrator")){
            outPrint += "<p><span class=\"fw-semibold\">注册时间:  &nbsp;&nbsp;</span>"+sdf.format(user.getCreateTime())+"</p>";
        }
        outPrint += "<p><span class=\"fw-semibold\">学号:  &nbsp;&nbsp;</span>"+user.getStudentID()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">学院:  &nbsp;&nbsp;</span>"+user.getCollege()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">联系电话:  &nbsp;&nbsp;</span>"+user.getTelephone()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">电子邮箱:  &nbsp;&nbsp;</span>"+user.getEmail()+"</p>";
        outPrint += "<p><span class=\"fw-semibold\">userID:  &nbsp;&nbsp;</span>"+user.getUserID()+"</p>";
        out.write(outPrint);
    }
}
